package com.wangyadong.hobby.schedule.jobtask.teststack;

import com.wangyadong.hobby.schedule.jobtask.tree.pq.Entry;

import java.util.Iterator;

/**
 * <p>
 *
 * @author <714037465@qq.com>
 * @since 2018/9/2715:08
 **/
public abstract class AbstractMapExample<K, V> implements Map<K, V> {

    @Override
    public boolean isEmpty() {
        return size() == 0;
    }

    private static class MapEntry<K, V> implements Entry<K, V> {
        private K k;
        private V v;

        public MapEntry(K key, V value) {
            this.k = key;
            this.v = value;
        }

        public void setK(K k) {
            this.k = k;
        }

        public void setV(V v) {
            this.v = v;
        }

        public K getKey() {
            return k;
        }

        public V getValue() {
            return v;
        }
    }

    private class keyIterator implements Iterator<K> {
        private Iterator<Entry<K, V>> entrys = entrySet().iterator();

        public boolean hasNext() {
            return entrys.hasNext();
        }

        public K next() {
            return entrys.next().getKey();
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }
    }

    private class KeyIterable implements Iterable<K> {
        public Iterator iterator() {
            return new keyIterator();
        }
    }

    private Iterator keySet() {
        return new KeyIterable().iterator();
    }

    private class ValueIterator implements Iterator<V> {
        private Iterator<Entry<K, V>> iterator = entrySet().iterator();

        public boolean hasNext() {
            return iterator.hasNext();
        }
        public V  next(){
            return iterator.next().getValue();
        }
    }

    private class  ValueIterable implements Iterable<V>{
        public Iterator iterator(){
            return new ValueIterator();
        }
    }

    public Iterator ValuesSet(){
        return new ValueIterable().iterator();
    }
}
